package svgedit.gui.command;

import svgedit.gui.View;
import svgedit.gui.controlpoints.ControlPoint;

/**
 *  Define resize exectution as a command object with functions
 *     execute (redo) and undo
 * */
public class ResizeCommand implements Command{
	
	private ControlPoint controlPoint;
	private ControlPoint backupPoint;
	private View view;
	private int x;
	private int y;
	private int initX;
	private int initY;
	
	/**
	 *  Constructor for resize command class
	 *  
	 *  @param view to get view object
	 *  @param controlPoint to get controlPoint object
	 *  @param x to get the new difference of x coordinate
	 *  @param y to get the new difference of y coordinate
	 *  @param initX to get the original difference of x coordinate
	 *  @param initY to get the original difference of y coordinate
	 * */
	public ResizeCommand(View view, ControlPoint controlPoint, int x, int y , int initX, int initY){
		this.view = view;
		this.controlPoint = controlPoint;
		this.x = x;
		this.y = y;
		this.initX = initX;
		this.initY = initY;
		backupPoint = null;
		
	}
	
	/**
	 *   Execute when resize the elements
	 *      or redo the resize the elements
	 * */
	public void execute(){
		if(backupPoint == null){
			backupPoint = controlPoint;
		}else{
			controlPoint.set(x, y);
			view.repaint();
		}
		 
	}
	
	/**
	 *  Undo the resize method to recover the elements original size
	 * */
	public void undo(){
		backupPoint.set(initX, initY);
		view.repaint();
	}

}
